#include "PlayListItem.h"
#include "common.h"

PlayListItem::PlayListItem(wxString _path) {
	//unsigned int len = _path.Length();
	//if (len > 8192) return;		/// пусть копирует поближе :)
	path = _path;
	void *module = ay_getsonginfo(path);
	isChipModule = 0;		/// if no music detected
	if (module) {
		isChipModule = 1;
		author = kickOffSpaces(wxString(ay_getsongauthor(module)));
		songname = kickOffSpaces(wxString(ay_getsongname(module)));

		duration = ay_getsonglength(module);
		unsigned long minute = duration / (50 * 60);
		displayInfo = songname + wxString::FromAscii(" ") + author;
		int empty = 1;
		for(unsigned int i = 0; i < displayInfo.Len(); i++) {
			if (displayInfo.ToAscii()[i] != ' ') {
				empty = 0;
				break;
			}
		}
		if (empty) {
			int i = path.Length();
			while (!(path[i] == '/' || path[i] == '\\') && i) {
				i--;
			};
			displayInfo = &path[i+1];
		}
		durationStr = wxString::Format(wxString::FromAscii("%02u:%02u"), minute, duration/50 - 60*minute);
		ay_closesong(&module);	/// heh vjaaka, memory limited :)
	}
}

PlayListItem::PlayListItem(wxString _path, wxString dispInfo, int _duration) {
	path = _path;
	displayInfo = dispInfo;
	duration = _duration;
	unsigned long minute = duration / (50 * 60);
	durationStr = wxString::Format(wxString::FromAscii("%02u:%02u"), minute, duration/50 - 60*minute);
}	/// very fast :)	suxx, slow, but faster old method


wxString PlayListItem::kickOffSpaces(wxString str) {
	str.Trim();
	str.Trim(false);
	return str;
}
/*
void* PlayListItem::getModule() {
	if (!module) {
		module = ay_getsonginfo(path);
	}
	return module;
}
*/
PlayListItem::~PlayListItem() {
///	if (module) ay_closesong(&module);
	//if (path) delete path;
}

